﻿using BaseDll;
using CommonTools;
using MotionIoLib;
using Newtonsoft.Json;
using OtherDevice;
using StationDemo.设备信息;
using StationDemo.设备信息.data;
using StationDemo.设备信息.helper;
using Sunny.UI;
using System;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using UserData;
using UserData.数据保存;

namespace StationDemo
{
    public class Param_CamTriTest
    {
        public ParamSet 是否屏蔽当前工位 = new ParamSet()
        {
            _enuValType = ParamSetUnit.boolUnit,
            _strParamUnit = "是否屏蔽当前工位",
            _strParamValMax = true,
            _strParamValMin = false,
            _strParamVal = false,
            _ParamRight = UserRight.Operator,
            _ParamClass = "综合",
            b_IsStartCheck = true,
        };

        //public ParamSet 提前扫码 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.boolUnit,
        //    _strParamUnit = "提前扫码",
        //    _strParamValMax = true,
        //    _strParamValMin = false,
        //    _strParamVal = false,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};

        //public ParamSet 触发超时时间 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.intUnit,
        //    _strParamUnit = "触发超时时间",
        //    _strParamValMax = 10000,
        //    _strParamValMin = 0,
        //    _strParamVal = 1000,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};

        //public ParamSet 扫码超时时间 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.intUnit,
        //    _strParamUnit = "扫码超时时间",
        //    _strParamValMax = 6000000,
        //    _strParamValMin = 0,
        //    _strParamVal = 600000,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};

        //public ParamSet 轴到位后延时 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.intUnit,
        //    _strParamUnit = "轴到位后延时",
        //    _strParamValMax = 600000,
        //    _strParamValMin = 0,
        //    _strParamVal = 500,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 读取标定数据后_是否重新点亮 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.boolUnit,
        //    _strParamUnit = "读取标定数据后_是否重新点亮",
        //    _strParamValMax = true,
        //    _strParamValMin = false,
        //    _strParamVal = false,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};

        //public ParamSet 三角测试点位1最小值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位1最小值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位1最大值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位1最大值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位2最小值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位2最小值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位2最大值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位2最大值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位3最小值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位3最小值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位3最大值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位3最大值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位4最小值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位4最小值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位4最大值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位4最大值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位5最小值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位5最小值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位5最大值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位5最大值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位6最小值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位6最小值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位6最大值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位6最大值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位7最小值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位7最小值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位7最大值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位7最大值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位8最小值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位8最小值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位8最大值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位8最大值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位9最小值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位9最小值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位9最大值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位9最大值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位10最小值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位10最小值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位10最大值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位10最大值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位11最小值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位11最小值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位11最大值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位11最大值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位12最小值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位12最小值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位12最大值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位12最大值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位13最小值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位13最小值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位13最大值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位13最大值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位14最小值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位14最小值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位14最大值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位14最大值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位15最小值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位15最小值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位15最大值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位15最大值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位16最小值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位16最小值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
        //public ParamSet 三角测试点位16最大值 = new ParamSet()
        //{
        //    _enuValType = ParamSetUnit.doubleUnit,
        //    _strParamUnit = "三角测试点位16最大值",
        //    _strParamValMax = 1,
        //    _strParamValMin = -1,
        //    _strParamVal = -0.3,
        //    _ParamRight = UserRight.Operator,
        //    _ParamClass = "综合",
        //    b_IsStartCheck = true,
        //};
    }
    public class Point_CamTriTest
    {
        public PointInfo 安全位置 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 上下料位置 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");

        public PointInfo 测试位置1 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置2 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置3 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置4 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置5 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置6 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置7 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置8 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置9 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置10 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置11 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置12 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置13 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置14 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置15 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置16 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");


    }
    public class Config_CamTriTest
    {
        [Category("工站参数"), DisplayName("扫码枪"), Description("扫码枪")]
        public string str_扫码枪 { set; get; } = "扫码枪";

        [Category("工站参数"), DisplayName("NG盒"), Description("NG盒")]
        public string str_NG盒 { set; get; } = "";
    }

    public class Station_三角测量 : CommonTools.StationbaseEx<Param_CamTriTest, Point_CamTriTest, Config_CamTriTest>
    {
        #region 变量

        //private int nUPHIndex = 0;

        private StationData stationData = null;

        public static bool isGetSN = false;
        public static string newSN = "";

        public Station_三角测量(CommonTools.Stationbase station, Param_CamTriTest param, Point_CamTriTest point, Config_CamTriTest config) : base(station, param, point, config)
        {

        }

        ClylinerBase ClylinerBase_NG盒 => DeviceMgr.GetInstance().Function_获取气缸(station_Config.str_NG盒) as ClylinerBase;



        public enum StationStep
        {
            [Description("初始化步骤")]
            StepInit,

            [Description("等待托盘停止")]
            StepWaitTableStop,

            [Description("获取产品信息")]
            StepCheckStation,

            #region 上料流程    

            [Description("上料测试")]
            StepLoad,

            [Description("等待SN")]
            StepWaitSN,

            [Description("下料测试")]
            Step下料,

            [Description("等待启动按钮")]
            StepWaitPushButton,

            [Description("点亮")]
            Step点亮,

            [Description("读取标定数据")]
            Step读取标定数据,

            #endregion

            #region 右工位流程

            [Description("右工位测试")]
            StepTestRight,

            [Description("右工位三角")]
            Step三角测试右,

            #endregion

            #region 对立工位流程

            [Description("对面工位测试")]
            StepTestOpposite,

            [Description("右工位三角")]
            Step三角测试Opposite,
            #endregion

            #region 左工位流程

            [Description("对面工位测试")]
            StepTestLeft,

            [Description("右工位三角")]
            Step三角测试Left,

            #endregion

            [Description("结束流程")]
            StepEnd,
        }
        #endregion

        #region 主流程
        protected override void StationWork(int step)
        {
            Thread.Sleep(50);
            try
            {
                switch (step)
                {
                    case (int)StationStep.StepInit:
                        DelCurrentStep();
                        PushMultStep((int)StepInitRun());
                        break;
                    case (int)StationStep.StepWaitTableStop:
                        DelCurrentStep();
                        PushMultStep((int)StepWaitTableStop());
                        break;
                    case (int)StationStep.StepCheckStation:
                        DelCurrentStep();
                        PushMultStep((int)StepCheckStation());
                        break;
                    case (int)StationStep.StepLoad:
                        DelCurrentStep();
                        PushMultStep((int)StepLoad());
                        break;
                    case (int)StationStep.StepWaitSN:
                        DelCurrentStep();
                        PushMultStep((int)StepWaitSN());
                        break;
                    case (int)StationStep.Step下料:
                        DelCurrentStep();
                        PushMultStep((int)Step下料());
                        break;
                    case (int)StationStep.StepWaitPushButton:
                        DelCurrentStep();
                        PushMultStep((int)StepWaitPushButton());
                        break;
                    case (int)StationStep.Step点亮:
                        DelCurrentStep();
                        PushMultStep((int)Step点亮());
                        break;
                    case (int)StationStep.Step读取标定数据:
                        DelCurrentStep();
                        PushMultStep((int)Step读取标定数据());
                        break;

                    case (int)StationStep.StepTestRight:
                        DelCurrentStep();
                        PushMultStep((int)StepTestRight());
                        break;

                    case (int)StationStep.Step三角测试右:
                        DelCurrentStep();
                        PushMultStep((int)Step三角测试右());
                        break;
                    case (int)StationStep.StepTestOpposite:
                        DelCurrentStep();
                        PushMultStep((int)StepTestOpposite());
                        break;

                    case (int)StationStep.Step三角测试Opposite:
                        DelCurrentStep();
                        PushMultStep((int)Step三角测试Opposite());
                        break;
                    case (int)StationStep.StepTestLeft:
                        DelCurrentStep();
                        PushMultStep((int)StepTestLeft());
                        break;

                    case (int)StationStep.Step三角测试Left:
                        DelCurrentStep();
                        PushMultStep((int)Step三角测试Left());
                        break;
                    case (int)StationStep.StepEnd:
                        DelCurrentStep();
                        PushMultStep((int)StepEnd());
                        break;
                }
            }
            catch (Exception ex)
            {
                LogHelper.OnTest_ShowLog(Name, $"{Name} 发生错误:{ex.StackTrace},{ex.Message}", LogType.Err);
                StationMgr.GetInstance().Stop();
            }
        }

        protected override bool InitStation()
        {
            ClearAllStep();
            PushMultStep((int)StationStep.StepInit);
            return true;
        }

        public override void PauseDeal()
        {

        }

        public override void ResumeDeal()
        {

        }

        public override void StopDeal()
        {

        }

        public StationStep StepInitRun(bool bmanual = false)
        {
            StationStateHelper.OnTest_ShowStep(Name, "已启动测试", LogType.Warn);
            return StationStep.StepWaitTableStop;
        }

        public StationStep StepWaitTableStop(bool bmanual = false)
        {
            StationStateHelper.OnTest_ShowStep(Name, "等待转盘停止", LogType.Warn);

            Station stat = (Station)Enum.Parse(typeof(Station), Name);
            if (StationHelper.Station_Table.GetWorkStatus(stat))
            {
                return StationStep.StepWaitTableStop;
            }

            if (station_Param.是否屏蔽当前工位._strParamVal)
            {
                return StationStep.StepEnd;
            }

            LogHelper.OnTest_ShowLog(Name, $"[{Name}]转盘停止，开始工作", LogType.Info);
            return StationStep.StepCheckStation;
        }

        public StationStep StepCheckStation(bool bmanual = false)
        {
            StationStateHelper.OnTest_ShowStep(Name, "获取当前工位信息", LogType.Warn);

            Station stat = (Station)Enum.Parse(typeof(Station), Name);
            (StationData stationData, int index) = StationHelper.Station_Table.StationDataByName(stat);
            this.stationData = ClassCloneHelper.Clone(stationData);

            LogHelper.OnTest_ShowLog(Name, $"位置[{index}]");

            switch (index)
            {
                case 0:// 当前治具在0号工位上
                    return StationStep.StepLoad; break;
                case 1:// 当前治具在1号工位上
                    return StationStep.StepTestRight; break;
                case 2:// 当前治具在2号工位上
                    return StationStep.StepTestOpposite; break;
                case 3:// 当前治具在3号工位上
                    return StationStep.StepTestLeft; break;
            }

            return StationStep.StepInit;
        }

        #region 上料工位测试流程

        public StationStep StepLoad(bool bmanual = false)
        {
            StationStateHelper.OnTest_ShowStep(Name, $"[{Name}]开始上料工位流程", LogType.Warn);
            LogHelper.OnTest_ShowLog(Name, $"[{Name}]开始上料工位流程,工位数据：\n{JsonConvert.SerializeObject(this.stationData)}", LogType.Warn);

            // 先运动到上料位置
            if (sys.g_AppMode == AppMode.Run)
            {
                Function_运动到点位(station_Point.上下料位置);
            }

            switch (stationData.Status)
            {
                case StationStatus.NoProduct:
                    {
                        LogHelper.OnTest_ShowLog(Name, $"[{Name}]当前工位无产品，下一步等待条码", LogType.Warn);
                        return StationStep.StepWaitSN;
                    }
                    break;
                case StationStatus.EndTest:
                    {
                        LogHelper.OnTest_ShowLog(Name, $"[{Name}]当前工位有产品，产品已测试完成，开始下料", LogType.Warn);
                        return StationStep.Step下料;
                    }
                    break;
                case StationStatus.HavaCantTest:
                case StationStatus.WaitTestRight:
                case StationStatus.WaitTestOpposite:
                case StationStatus.WaitTestLeft:
                    {
                        LogHelper.OnTest_ShowLog(Name, $"[{Name}]当前工位状态不符合，结束流程", LogType.Warn);
                        return StationStep.StepEnd;
                    }
                    break;
                default:
                    return StationStep.StepEnd;
                    break;
            }
        }

        public StationStep StepWaitSN(bool bmanual = false)
        {

            if (UserConfig.CleanProduct)
            {
                UserConfig.CleanProduct = false;
                LogHelper.OnTest_ShowLog(Name, $"[{Name}]接收到清料命令", LogType.Warn);
                Thread.Sleep(3000);
                return StationStep.StepEnd;
            }

            if (isGetSN)
            {
                isGetSN = false;
                this.stationData.TestResult = new 设备信息.TestResult();
                stationData.TestResult.str_外壳SN.Value = newSN;
                stationData.TestResult.time_当前时间.Value = DateTime.Now;
                StationStateHelper.OnTest_ShowStep(Name, $"SN:[{newSN}]", LogType.Warn);
                LogHelper.OnTest_ShowLog(Name, $"[{Name}]获取到新的SN:{newSN},下一步等待启动按钮", LogType.Info);
                return StationStep.StepWaitPushButton;
            }

            return StationStep.StepWaitSN;
        }

        public StationStep Step下料(bool bmanual = false)
        {
            GlobalVariable.启用安全光栅 = false;

            if (sys.g_AppMode == AppMode.Run)
                LoadSeverMgr.Instance.Functio_停止取图();

            DateTime st = stationData.TestResult.time_当前时间.Value;
            DateTime et = DateTime.Now;
            stationData.TestResult.time_结束时间.Value = et;
            stationData.TestResult.CT.Value = (et - st).TotalSeconds;
            stationData.TestResult.治具.Value = this.Name;

            SaveCSV();
            //表格结果显示
            ProductDataShow.OnTest_ShowProductData(stationData.TestResult);
            TestTimeMgr.GetInstance().Function_AddTestTime("数据统计", stationData.TestResult.CT.Value, stationData.TestResult.测试结果.Value);

            double tsum = 0;
            tsum += stationData.TestResult.ErrValue1.Value;
            tsum += stationData.TestResult.ErrValue2.Value;
            tsum += stationData.TestResult.ErrValue3.Value;
            tsum += stationData.TestResult.ErrValue4.Value;
            tsum += stationData.TestResult.ErrValue5.Value;
            tsum += stationData.TestResult.ErrValue6.Value;
            tsum += stationData.TestResult.ErrValue7.Value;
            tsum += stationData.TestResult.ErrValue8.Value;
            tsum += stationData.TestResult.ErrValue9.Value;
            tsum += stationData.TestResult.ErrValue10.Value;
            tsum += stationData.TestResult.ErrValue11.Value;
            tsum += stationData.TestResult.ErrValue12.Value;
            tsum += stationData.TestResult.ErrValue13.Value;
            tsum += stationData.TestResult.ErrValue14.Value;
            tsum += stationData.TestResult.ErrValue15.Value;
            tsum += stationData.TestResult.ErrValue16.Value;

            LogHelper.OnTest_ShowLog(Name, $"误差平均值:{tsum / 16}", LogType.Info);

            if (sys.g_AppMode == AppMode.AirRun)
            {
                return StationStep.StepWaitSN;
            }
            if (!stationData.TestResult.测试结果.Value)
            {
                Form_Auto.FlashResult("NG");
                ClylinerBase_NG盒?.Function_后退();
                stationData.TestResult.最终结果.Value = "Fail";
                StationStateHelper.OnTest_ShowStep(Name, "请下NG料", LogType.Warn);
                // PathHelper.CopyDir(PathHelper.ImageOKPath, PathHelper.ImageNGPath);
                //while (IOMgr.GetInstace().Function_ReCheckIO(IO_IN.NG光栅1.ToString(), false, 200) || IOMgr.GetInstace().Function_ReCheckIO(IO_IN.NG光栅2.ToString(), false, 200))
                //{
                //    if (Param_System.Instance.是否屏蔽NG盒._strParamVal)
                //    {
                //        break;
                //    }
                //    Thread.Sleep(100);
                //}

                LogHelper.OnTest_ShowLog(Name, $"三角标定完成NG，SN码={stationData.TestResult.str_外壳SN.Value}，CT={stationData.TestResult.CT.Value.ToString("0.00")}s", LogType.Err);
            }
            else
            {
                Form_Auto.FlashResult("Pass");
                LogHelper.OnTest_ShowLog(Name, $"三角标定完成OK，SN码={stationData.TestResult.str_外壳SN.Value}，CT={stationData.TestResult.CT.Value.ToString("0.00")}s", LogType.Info);
            }

            return StationStep.StepWaitSN;
        }

        public StationStep StepWaitPushButton(bool bmanual = false)
        {
            if (/*IO_IN.人工位启动信号.Get()*/true)
            {
                GlobalVariable.启用安全光栅 = true;
                LogHelper.OnTest_ShowLog(Name, $"[{Name}]检测到人工启动，下一步点亮测试", LogType.Info);
                return StationStep.Step点亮;
            }
            else
            {
                return StationStep.StepWaitSN;
            }
        }

        public StationStep Step点亮(bool bmanual = false)
        {
            StationStateHelper.OnTest_ShowStep(Name, "开始点亮", LogType.Info);
            LogHelper.OnTest_ShowLog(Name, $"开始点亮", LogType.Info);

            if (sys.g_AppMode == AppMode.AirRun)
            {
                Thread.Sleep(1000);
                return StationStep.Step读取标定数据;
            }

            //点亮
            for (int i = 0; i < 3; i++)
            {
                LogHelper.OnTest_ShowLog(Name, $"第{i + 1}次点亮", LogType.Warn);
                StationStateHelper.OnTest_ShowStep(Name, $"第{i + 1}次点亮", LogType.Warn);

                bool cap = LoadSeverMgr.Instance.Function_点亮(stationData.TestResult.str_外壳SN.Value);
                if (cap)
                {
                    LogHelper.OnTest_ShowLog(Name, $"第{i + 1}次点亮成功，下一步开始读取标定数据", LogType.Info);
                    return StationStep.Step读取标定数据;
                }
                else
                {
                    LogHelper.OnTest_ShowLog(Name, $"第{i + 1}次点亮失败", LogType.Err);
                    StationStateHelper.OnTest_ShowStep(Name, $"第{i + 1}次点亮失败", LogType.Err);
                }
            }

            // 点亮失败也得计算在结果里
            this.stationData.TestResult.测试结果.Value = false;
            this.stationData.TestResult.FailStep.Value += "#点亮";
            SaveCSV();
            LogHelper.OnTest_ShowLog(Name, $"点亮失败,请换料", LogType.Err);
            StationStateHelper.OnTest_ShowStep(Name, "点亮失败,请换料", LogType.Err);
            return StationStep.StepWaitSN;
        }

        public StationStep Step读取标定数据(bool bmanual = false)
        {
            StationStateHelper.OnTest_ShowStep(Name, "开始获取标定数据", LogType.Info);
            LogHelper.OnTest_ShowLog(Name, $"开始获取标定数据", LogType.Info);

            if (sys.g_AppMode != AppMode.AirRun)
            {
                if (!LoadSeverMgr.Instance.Function_读取标定数据())
                {
                    LogHelper.OnTest_ShowLog(Name, $"Function_读取标定数据失败", LogType.Err);
                    StationStateHelper.OnTest_ShowStep(Name, "Function_读取标定数据失败", LogType.Err);
                    this.stationData.TestResult.测试结果.Value = false;
                    this.stationData.TestResult.FailStep.Value += "#读取标定数据";
                    SaveCSV();
                    return StationStep.StepWaitSN;
                }
                else
                {
                    StationStateHelper.OnTest_ShowStep(Name, "开始获取标定数据完成", LogType.Info);
                    LogHelper.OnTest_ShowLog(Name, $"开始获取标定数据完成", LogType.Info);
                }

                if (/*station_Param.读取标定数据后_是否重新点亮._strParamVal*/false)
                {
                    StationStateHelper.OnTest_ShowStep(Name, "重新点亮", LogType.Info);
                    LogHelper.OnTest_ShowLog(Name, $"重新点亮", LogType.Info);
                    LoadSeverMgr.Instance.Functio_停止取图();
                    Thread.Sleep(500);
                    //点亮
                    for (int i = 0; i < 3; i++)
                    {
                        LogHelper.OnTest_ShowLog(Name, $"第{i + 1}次点亮失败", LogType.Info);

                        bool cap = LoadSeverMgr.Instance.Function_点亮(stationData.TestResult.str_外壳SN.Value);
                        if (cap)
                        {
                            LogHelper.OnTest_ShowLog(Name, $"第{i + 1}次点亮成功，下一步开始读取标定数据", LogType.Info);
                            return StationStep.StepEnd;
                        }
                    }
                }

                this.stationData.Status = StationStatus.WaitTestRight;
                return StationStep.StepEnd;
            }
            else
            {
                if (StationHelper.Station_Table.station_Param.顺时针转动._strParamVal)
                    this.stationData.Status = StationStatus.WaitTestLeft;
                else
                    this.stationData.Status = StationStatus.WaitTestRight;
                StationStateHelper.OnTest_ShowStep(Name, "空跑，已屏蔽获取标定数据", LogType.Info);
                LogHelper.OnTest_ShowLog(Name, $"空跑，已屏蔽获取标定数据", LogType.Info);
            }
            return StationStep.StepEnd;
        }

        #endregion

        #region 右工位测试流程

        public StationStep StepTestRight(bool bmanual = false)
        {
            StationStateHelper.OnTest_ShowStep(Name, $"[{Name}]开始右工位流程", LogType.Warn);
            LogHelper.OnTest_ShowLog(Name, $"[{Name}]开始右工位流程,工位数据：\n{JsonConvert.SerializeObject(this.stationData)}", LogType.Warn);

            switch (stationData.Status)
            {
                case StationStatus.NoProduct:
                    LogHelper.OnTest_ShowLog(Name, $"[{Name}]当前工位无产品，流程结束", LogType.Err);
                    return StationStep.StepEnd;
                case StationStatus.HavaCantTest:
                    LogHelper.OnTest_ShowLog(Name, $"[{Name}]当前工位有产品，但是无法测试", LogType.Err);
                    return StationStep.StepEnd;
                case StationStatus.WaitTestRight:
                    LogHelper.OnTest_ShowLog(Name, $"[{Name}]当前工位有产品，符合测试条件，开始测试", LogType.Info);
                    return StationStep.Step三角测试右;
                case StationStatus.WaitTestOpposite:
                case StationStatus.WaitTestLeft:
                case StationStatus.EndTest:
                    LogHelper.OnTest_ShowLog(Name, $"[{Name}]当前工位有产品，但是应该在{stationData.Status}工位测试", LogType.Err);
                    return StationStep.StepEnd;
                default:
                    LogHelper.OnTest_ShowLog(Name, $"[{Name}]未知流程[{stationData.Status.ToString()}]", LogType.Err);
                    return StationStep.StepEnd;
            }
        }

        public StationStep Step三角测试右(bool bmanual = false)
        {
            bool b_Result = true;
            StationStateHelper.OnTest_ShowStep(Name, $"{Name}开始三角测试 右", LogType.Warn);
            LogHelper.OnTest_ShowLog(Name, $"{Name}开始三角测试 右", LogType.Warn);

            double[] data = new double[16];
            PointInfo point = station_Point.测试位置1;
            if (sys.g_AppMode != AppMode.AirRun)
                Function_运动到点位(point, bmanual);
            //Thread.Sleep(station_Param.轴到位后延时._strParamVal);

            if (sys.g_AppMode == AppMode.Run)
                LoadSeverMgr.Instance.Function_三角取图(0);
            FieldInfo[] fields = station_Point.GetType().GetFields();
            for (int i = 1; i < 9; i++)
            {
                foreach (FieldInfo temp in fields)
                {
                    if (temp.Name == $"测试位置{i + 1}")
                    {
                        if (sys.g_AppMode == AppMode.AirRun)
                        {
                            Thread.Sleep(500);
                            continue;
                        }
                        PointInfo pointInfo = (PointInfo)temp.GetValue(station_Point);
                        Function_运动到点位(pointInfo, bmanual);
                        data[i - 1] = i - 1;
                        if (sys.g_AppMode == AppMode.Run)
                            b_Result &= LoadSeverMgr.Instance.Function_三角标定(ref data[i - 1]);
                        //Thread.Sleep(station_Param.轴到位后延时._strParamVal);
                        if (sys.g_AppMode == AppMode.Run)
                            b_Result &= LoadSeverMgr.Instance.Function_三角取图(i);
                    }
                }
            }

            this.stationData.TestResult.ErrValue1.Value = data[0];
            this.stationData.TestResult.ErrValue2.Value = data[1];
            this.stationData.TestResult.ErrValue3.Value = data[2];
            this.stationData.TestResult.ErrValue4.Value = data[3];
            this.stationData.TestResult.ErrValue5.Value = data[4];
            this.stationData.TestResult.ErrValue6.Value = data[5];
            this.stationData.TestResult.ErrValue7.Value = data[6];
            this.stationData.TestResult.ErrValue8.Value = data[7];
            this.stationData.TestResult.ErrValue9.Value = data[8];

            LogHelper.OnTest_ShowLog(Name, $"右工位测试完成", LogType.Info);

            StationStateHelper.OnTest_ShowStep(Name, "预备到下工位", LogType.Info);
            LogHelper.OnTest_ShowLog(Name, $"预备到下工位", LogType.Info);
            if (StationHelper.Station_Table.station_Param.顺时针转动._strParamVal)
                this.stationData.Status = StationStatus.EndTest;
            else
                this.stationData.Status = StationStatus.WaitTestOpposite;
            return StationStep.StepEnd;
        }

        #endregion

        #region 对立工位测试流程

        public StationStep StepTestOpposite(bool bmanual = false)
        {
            StationStateHelper.OnTest_ShowStep(Name, $"[{Name}]开始对立工位流程", LogType.Warn);
            LogHelper.OnTest_ShowLog(Name, $"[{Name}]开始对立工位流程,工位数据：\n{JsonConvert.SerializeObject(this.stationData)}", LogType.Warn);

            switch (stationData.Status)
            {
                case StationStatus.NoProduct:
                    LogHelper.OnTest_ShowLog(Name, $"[{Name}]当前工位无产品，流程结束", LogType.Err);
                    return StationStep.StepEnd;
                case StationStatus.HavaCantTest:
                    LogHelper.OnTest_ShowLog(Name, $"[{Name}]当前工位有产品，但是无法测试", LogType.Err);
                    return StationStep.StepEnd;
                case StationStatus.WaitTestOpposite:
                    LogHelper.OnTest_ShowLog(Name, $"[{Name}]当前工位有产品，符合测试条件，开始测试", LogType.Info);
                    return StationStep.Step三角测试Opposite;
                case StationStatus.WaitTestRight:
                case StationStatus.WaitTestLeft:
                case StationStatus.EndTest:
                    LogHelper.OnTest_ShowLog(Name, $"[{Name}]当前工位有产品，但是应该在{StationStatus.WaitTestOpposite}工位测试", LogType.Err);
                    return StationStep.StepEnd;
                default:
                    LogHelper.OnTest_ShowLog(Name, $"[{Name}]未知流程[{stationData.Status.ToString()}]", LogType.Err);
                    return StationStep.StepEnd;
            }
        }

        public StationStep Step三角测试Opposite(bool bmanual = false)
        {
            bool b_Result = true;
            StationStateHelper.OnTest_ShowStep(Name, $"{Name}开始三角测试 Opposite", LogType.Warn);
            LogHelper.OnTest_ShowLog(Name, $"{Name}开始三角测试 Opposite", LogType.Warn);

            double[] data = new double[16];
            PointInfo point = station_Point.测试位置1;
            if (sys.g_AppMode == AppMode.Run)
                Function_运动到点位(point, bmanual);
            //Thread.Sleep(station_Param.轴到位后延时._strParamVal);

            if (sys.g_AppMode == AppMode.Run)
                LoadSeverMgr.Instance.Function_三角取图(0);
            FieldInfo[] fields = station_Point.GetType().GetFields();
            for (int i = 10; i < 16; i++)
            {
                foreach (FieldInfo temp in fields)
                {
                    if (temp.Name == $"测试位置{i + 1}")
                    {
                        PointInfo pointInfo = (PointInfo)temp.GetValue(station_Point);
                        if (sys.g_AppMode == AppMode.Run)
                            Function_运动到点位(pointInfo, bmanual);
                        data[i - 1] = i - 1;
                        if (sys.g_AppMode == AppMode.Run)
                            b_Result &= LoadSeverMgr.Instance.Function_三角标定(ref data[i - 1]);
                        //.Sleep(station_Param.轴到位后延时._strParamVal);
                        if (sys.g_AppMode == AppMode.Run)
                            b_Result &= LoadSeverMgr.Instance.Function_三角取图(i);
                    }
                }
            }
            data[15] = 15;
            if (sys.g_AppMode == AppMode.Run)
                b_Result &= LoadSeverMgr.Instance.Function_三角标定(ref data[15]);

            stationData.TestResult.ErrValue10.Value = data[9];
            stationData.TestResult.ErrValue11.Value = data[10];
            stationData.TestResult.ErrValue12.Value = data[11];
            stationData.TestResult.ErrValue13.Value = data[12];
            stationData.TestResult.ErrValue14.Value = data[13];
            stationData.TestResult.ErrValue15.Value = data[14];
            stationData.TestResult.ErrValue16.Value = data[15];

            Function_SetLimit();

            string errMsg = "";
            bool v = Func_数据对比(stationData.TestResult, ref errMsg);
            if (!v)
            {
                stationData.TestResult.最终结果.Value = false;
                stationData.TestResult.FailStep.Value += "#结果NG";
            }


            LogHelper.OnTest_ShowLog(Name, $"中工位测试完成", LogType.Info);

            StationStateHelper.OnTest_ShowStep(Name, "预备到下工位", LogType.Info);
            LogHelper.OnTest_ShowLog(Name, $"预备到下料位", LogType.Info);
            if (StationHelper.Station_Table.station_Param.顺时针转动._strParamVal)
                this.stationData.Status = StationStatus.WaitTestRight;
            else
                this.stationData.Status = StationStatus.WaitTestLeft;
            return StationStep.StepEnd;
        }


        #endregion

        #region 左工位测试流程

        public StationStep StepTestLeft(bool bmanual = false)
        {
            StationStateHelper.OnTest_ShowStep(Name, $"[{Name}]开始左工位流程", LogType.Warn);
            LogHelper.OnTest_ShowLog(Name, $"[{Name}]开始左位流程,工位数据：\n{JsonConvert.SerializeObject(this.stationData)}", LogType.Warn);

            switch (stationData.Status)
            {
                case StationStatus.NoProduct:
                    LogHelper.OnTest_ShowLog(Name, $"[{Name}]当前工位无产品，流程结束", LogType.Err);
                    return StationStep.StepEnd;
                case StationStatus.HavaCantTest:
                    LogHelper.OnTest_ShowLog(Name, $"[{Name}]当前工位有产品，但是无法测试", LogType.Err);
                    return StationStep.StepEnd;
                case StationStatus.WaitTestLeft:
                    LogHelper.OnTest_ShowLog(Name, $"[{Name}]当前工位有产品，符合测试条件，开始测试", LogType.Info);
                    return StationStep.Step三角测试Left;
                case StationStatus.WaitTestRight:
                case StationStatus.WaitTestOpposite:
                case StationStatus.EndTest:
                    LogHelper.OnTest_ShowLog(Name, $"[{Name}]当前工位有产品，但是应该在{stationData.Status}工位测试", LogType.Err);
                    return StationStep.StepEnd;
                default:
                    LogHelper.OnTest_ShowLog(Name, $"[{Name}]未知流程[{stationData.Status.ToString()}]", LogType.Err);
                    return StationStep.StepEnd;
            }
        }

        public StationStep Step三角测试Left(bool bmanual = false)
        {
            if (!Param_System.Instance.是否屏蔽鱼眼箱._strParamVal)
            {
                // 测试
            }

            if (StationHelper.Station_Table.station_Param.顺时针转动._strParamVal)
                this.stationData.Status = StationStatus.WaitTestOpposite;
            else
                this.stationData.Status = StationStatus.EndTest;

            return StationStep.StepEnd;
        }

        public StationStep StepEnd(bool bmanual = false)
        {
            if (sys.g_AppMode == AppMode.Run)
                Function_运动到点位(station_Point.安全位置);
            Station stat = (Station)Enum.Parse(typeof(Station), Name);
            StationHelper.Station_Table.NotifyTable(stat, this.stationData);
            LogHelper.OnTest_ShowLog(Name, $"[{Name}]通知转盘流程结束", LogType.Warn);
            return StationStep.StepWaitTableStop;
        }

        #endregion

        //public StationStep Step_启动(bool bmanual = false)
        //{
        //Retry:
        //    StationStateHelper.OnTest_ShowStep(Name, "请上料，并按双启动按钮", LogType.Info);
        //    LogHelper.OnTest_ShowLog(Name, $"请上料，并按双启动按钮", LogType.Info);

        //    Stopwatch stopwatch = new Stopwatch();
        //    stopwatch.Start();
        //    while (sys.g_AppMode == AppMode.Run)
        //    {
        //        if (UserConfig.b_isScan)
        //            return StationStep.Step_扫码;
        //        if (IOMgr.GetInstace().Function_ReCheckIO(IO_IN.双启动信号.ToString(), true, 100))
        //        {
        //            IO_OUT.双启动指示灯.Set(false);
        //            break;
        //        }
        //        if (stopwatch.ElapsedMilliseconds > 1000)
        //        {
        //            IO_OUT.双启动指示灯.Set(!IO_OUT.双启动指示灯.Get());
        //            stopwatch.Restart();
        //        }
        //    }

        //    if (sys.g_AppMode == AppMode.AirRun)
        //    {
        //        for (int i = 0; i < 3; i++)
        //        {
        //            IO_OUT.双启动指示灯.Set(true);
        //            Thread.Sleep(1000);
        //            IO_OUT.双启动指示灯.Set(false);
        //            Thread.Sleep(1000);
        //        }
        //    }
        //    else
        //    {
        //        //if (IOMgr.GetInstace().Function_ReCheckIO(IO_IN.治具开合感应.ToString(), false, 100))
        //        //{
        //        //    AlarmMgr.GetIntance().WarnWithDlg((int)AlarmList.治具开合感应, new string[] { "重试" }, new string[] { "治具开合感应异常，请检查是否完成合盖操作" });
        //        //    goto Retry;
        //        //}
        //        //if (IOMgr.GetInstace().Function_ReCheckIO(IO_IN.产品有无感应.ToString(), false, 100))
        //        //{
        //        //    AlarmMgr.GetIntance().WarnWithDlg((int)AlarmList.产品有无感应, new string[] { "重试" }, new string[] { "产品有无感应异常，请检查是否放料" });
        //        //    goto Retry;
        //        //}
        //    }
        //    IO_OUT.双色灯红.Set(false);
        //    IO_OUT.双色灯绿.Set(false);

        //    SNHelper.OnTest_ReflushSN("SN");
        //    GlobalVariable.启用安全光栅 = true;
        //    UPHTimeMgr.Instance.AddData(nUPHIndex, Name, $"按下双启动");
        //    return StationStep.Step_点亮;
        //}

        //public StationStep Step_Test(bool bmanual = false)
        //{
        //    bool b_Result = true;
        //    StationStateHelper.OnTest_ShowStep(Name, "开始测试", LogType.Info);
        //    LogHelper.OnTest_ShowLog(Name, $"开始测试", LogType.Info);

        //    double[] data = new double[16];
        //    PointInfo point = station_Point.测试位置1;
        //    //LogHelper.OnTest_ShowLog(Name, $"测试位置：测试位置1 U轴目标位置：{point.pointU},Tx轴目标位置：{point.pointTx}", LogType.Err);
        //    Function_运动到点位(point, bmanual);
        //    Thread.Sleep(station_Param.轴到位后延时._strParamVal);

        //    if (sys.g_AppMode == AppMode.Run)
        //        LoadSeverMgr.Instance.Function_三角取图(0);
        //    FieldInfo[] fields = station_Point.GetType().GetFields();
        //    for (int i = 1; i < 16; i++)
        //    {
        //        foreach (FieldInfo temp in fields)
        //        {
        //            if (temp.Name == $"测试位置{i + 1}")
        //            {
        //                PointInfo pointInfo = (PointInfo)temp.GetValue(station_Point);
        //                //LogHelper.OnTest_ShowLog(Name, $"测试位置：{temp.Name} U轴目标位置：{pointInfo.pointU},Tx轴目标位置：{pointInfo.pointTx}", LogType.Err);
        //                Function_运动到点位(pointInfo, bmanual);
        //                data[i - 1] = i - 1;
        //                if (sys.g_AppMode == AppMode.Run)
        //                    b_Result &= LoadSeverMgr.Instance.Function_三角标定(ref data[i - 1]);
        //                Thread.Sleep(station_Param.轴到位后延时._strParamVal);
        //                if (sys.g_AppMode == AppMode.Run)
        //                    b_Result &= LoadSeverMgr.Instance.Function_三角取图(i);
        //            }
        //        }
        //    }
        //    data[15] = 15;
        //    if (sys.g_AppMode == AppMode.Run)
        //        b_Result &= LoadSeverMgr.Instance.Function_三角标定(ref data[15]);

        //    testResult.ErrValue1.Value = data[0];
        //    testResult.ErrValue2.Value = data[1];
        //    testResult.ErrValue3.Value = data[2];
        //    testResult.ErrValue4.Value = data[3];
        //    testResult.ErrValue5.Value = data[4];
        //    testResult.ErrValue6.Value = data[5];
        //    testResult.ErrValue7.Value = data[6];
        //    testResult.ErrValue8.Value = data[7];
        //    testResult.ErrValue9.Value = data[8];
        //    testResult.ErrValue10.Value = data[9];
        //    testResult.ErrValue11.Value = data[10];
        //    testResult.ErrValue12.Value = data[11];
        //    testResult.ErrValue13.Value = data[12];
        //    testResult.ErrValue14.Value = data[13];
        //    testResult.ErrValue15.Value = data[14];
        //    testResult.ErrValue16.Value = data[15];

        //    if (sys.g_AppMode == AppMode.Run && (!Func_数据对比(testResult, ref strError) || !b_Result))
        //    {
        //        testResult.测试结果.Value = false;
        //        testResult.FailStep.Value = strError;
        //        LogHelper.OnTest_ShowLog(Name, $"三角标定测试失败", LogType.Err);
        //        UPHTimeMgr.Instance.AddData(nUPHIndex, Name, $"测试完成");
        //    }

        //    LogHelper.OnTest_ShowLog(Name, $"测试完成", LogType.Info);
        //    UPHTimeMgr.Instance.AddData(nUPHIndex, Name, $"测试完成");


        //    StationStateHelper.OnTest_ShowStep(Name, "预备到下料位", LogType.Info);
        //    LogHelper.OnTest_ShowLog(Name, $"预备到下料位", LogType.Info);
        //    return StationStep.Step_下料;
        //}

        //public StationStep Step_下料(bool bmanual = false)
        //{
        //    StationStateHelper.OnTest_ShowStep(Name, "开始下料", LogType.Info);
        //    LogHelper.OnTest_ShowLog(Name, $"开始下料", LogType.Info);

        //    Function_运动到点位(station_Point.上下料位置);

        //    if (sys.g_AppMode == AppMode.AirRun)
        //    {
        //        LogHelper.OnTest_ShowLog(Name, $"空跑，已屏蔽测试", LogType.Info);
        //        return StationStep.Step_End;
        //    }

        //    GlobalVariable.启用安全光栅 = false;
        //    LoadSeverMgr.Instance.Functio_停止取图();

        //    double d_CTTime = (DateTime.Now - startTime).TotalSeconds;
        //    startTime = DateTime.Now;
        //    testResult.time_结束时间.Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

        //    //表格结果显示
        //    ProductDataShow.OnTest_ShowProductData(testResult);

        //    if (!testResult.测试结果.Value)
        //    {
        //        IO_OUT.双色灯绿.Set(false);
        //        IO_OUT.双色灯红.Set(true);
        //        Form_Auto.FlashResult("NG");
        //        ClylinerBase_NG盒?.Function_后退();
        //        testResult.最终结果.Value = "Fail";
        //        StationStateHelper.OnTest_ShowStep(Name, "请下NG料", LogType.Warn);
        //        // PathHelper.CopyDir(PathHelper.ImageOKPath, PathHelper.ImageNGPath);
        //        while (IOMgr.GetInstace().Function_ReCheckIO(IO_IN.NG光栅1.ToString(), false, 200) || IOMgr.GetInstace().Function_ReCheckIO(IO_IN.NG光栅2.ToString(), false, 200))
        //        {
        //            if (Param_System.Instance.是否屏蔽NG盒._strParamVal)
        //            {
        //                break;
        //            }
        //            Thread.Sleep(100);
        //        }

        //        StationStateHelper.OnTest_ShowStep(Name, $"三角标定完成NG，CT={d_CTTime.ToString("0.00")}s", LogType.Err);
        //        LogHelper.OnTest_ShowLog(Name, $"三角标定完成NG，SN码={testResult.str_外壳SN.Value}，CT={d_CTTime.ToString("0.00")}s", LogType.Err);
        //    }
        //    else
        //    {
        //        IO_OUT.双色灯绿.Set(true);
        //        IO_OUT.双色灯红.Set(false);
        //        Form_Auto.FlashResult("Pass");
        //        StationStateHelper.OnTest_ShowStep(Name, $"三角标定完成OK，CT={d_CTTime.ToString("0.00")}s", LogType.Info);
        //        LogHelper.OnTest_ShowLog(Name, $"三角标定完成OK，SN码={testResult.str_外壳SN.Value}，CT={d_CTTime.ToString("0.00")}s", LogType.Info);
        //    }
        //    string path = $@"D:\HY System\结果\{Param_System.Instance.机型._strParamVal}\{Param_System.Instance.批次._strParamVal}\{DateTime.Now.ToString("yyyy-MM-dd")}\三角测量\测试数据.csv";
        //    if (!Directory.Exists(Directory.GetParent(path).FullName))
        //    {
        //        Directory.CreateDirectory(Directory.GetParent(path).FullName);
        //    }
        //    CSVHelper.Instance.SaveToCSVPath(path, testResult, true);

        //    if (d_CTTime > Param_System.Instance.正常生产时长限制._strParamVal)
        //        d_CTTime = 0;
        //    TestTimeMgr.GetInstance().Function_AddTestTime("数据统计", d_CTTime, testResult.测试结果.Value);

        //    LogHelper.OnTest_ShowLog(Name, $"测试完成", LogType.Info);
        //    UPHTimeMgr.Instance.AddData(nUPHIndex, Name, $"测试完成");
        //    return StationStep.Step_End;
        //}

        //public StationStep StepNG(bool bmanual = false)
        //{
        //    StationStateHelper.OnTest_ShowStep(Name, "流程NG", LogType.Info);
        //    LogHelper.OnTest_ShowLog(Name, $"流程NG", LogType.Info);

        //    return StationStep.Step_End;
        //}

        private void SaveCSV()
        {
            string path = $@"D:\HY System\结果\{Param_System.Instance.机型._strParamVal}\{Param_System.Instance.批次._strParamVal}\{DateTime.Now:yyyy-MM-dd}\三角测量_测试数据.csv";
            if (!Directory.Exists(Directory.GetParent(path).FullName))
                Directory.CreateDirectory(Directory.GetParent(path).FullName);

            try
            {
                CSVHelper.Instance.SaveToCSVPath(path, this.stationData.TestResult, true);
            }
            catch (Exception ex)
            {
                LogHelper.OnTest_ShowLog(Name, ex.Message, LogType.Err);
                UIMessageBox.ShowError("检测到保存异常，如果是表格被人为打开请关闭，关闭后会再次保存");
                try
                {
                    CSVHelper.Instance.SaveToCSVPath(path, this.stationData.TestResult, true);
                }
                catch (Exception ex2)
                {
                    LogHelper.OnTest_ShowLog(Name, ex2.Message, LogType.Err);
                }
            }
        }

        #endregion

        #region  方法
        public bool Function_工站回零()
        {
            StationStateHelper.OnTest_ShowStep(Name, $"正在回零", LogType.Info);
            bool bResult = true;

            UserDefineFunction.Axis_回零(AxisTx, "AxisTx", this);
            UserDefineFunction.Axis_回零(AxisTy, "AxisTy", this);
            UserDefineFunction.Axis_回零(AxisU, "AxisU", this);

            StationStateHelper.OnTest_ShowStep(Name, $"回零完成", LogType.Info);

            LogHelper.OnTest_ShowLog(Name, "安全偏转");
            MoveMulitAxisPosWaitInpos(new int[] { AxisU }, new double[] { 10 }, new double[] { (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High }, 0.5, true, this);


            return bResult;
        }

        public bool Function_平行光管鱼眼箱回零()
        {
            StationStateHelper.OnTest_ShowStep(Name, $"平行光管正在回零", LogType.Info);

            bool bResult = true;

            Task task1 = Task.Run(() => UserDefineFunction.Axis_回零(AxisX, "右平行光管", this));
            Task task2 = Task.Run(() => UserDefineFunction.Axis_回零(AxisY, "后平行光管", this));
            Task task3 = Task.Run(() => UserDefineFunction.Axis_回零(AxisZ, "鱼眼箱", this));
            Task.WaitAll(new Task[] { task1, task2, task3 });

            LogHelper.OnTest_ShowLog(Name, $"平行光管鱼眼箱回零[{bResult}]");

            return bResult;
        }

        public bool Function_气缸复位(bool bmanual = false)
        {
            return true;
        }

        private void Function_运动到点位(PointInfo point, bool bmanual = false)
        {
            MoveMulitAxisPosWaitInpos(
                new int[] { AxisU, AxisTx, AxisTy },
                new double[] { point.pointU, point.pointTx, point.pointTy },
                new double[] { (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High },
                0.5, bmanual, this);
        }

        //public bool Function_扫码(ref string strSN)
        //{
        //    if (sys.g_AppMode == AppMode.AirRun)
        //    {
        //        strSN = "空跑";
        //        return true;
        //    }

        //    if (Param_System.Instance.是否屏蔽扫码._strParamVal)
        //    {
        //        strSN = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
        //        return true;
        //    }

        //    if (station_Param.键盘模式._strParamVal)
        //    {
        //        if (!station_Param.提前扫码._strParamVal)
        //            SNHelper.OnTest_ReflushSN("SN");
        //        Stopwatch stopwatch = new Stopwatch();
        //        stopwatch.Start();
        //        while (true)
        //        {
        //            if (GlobalVariable.g_StationState == StationState.StationStateEmg)
        //                return false;
        //            if (UserConfig.b_isScan)
        //            {
        //                strSN = UserConfig.str_SN;
        //                if (strSN != "")
        //                    break;
        //            }
        //            if (stopwatch.ElapsedMilliseconds > station_Param.扫码超时时间._strParamVal)
        //            {
        //                LogHelper.OnTest_ShowLog(Name, $"SN读取超时，读取内容=[{strSN}]", LogType.Err);
        //                StationStateHelper.OnTest_ShowStep(Name, $"{Name} SN读取超时", LogType.Warn);
        //                //AlarmMgr.GetIntance().WarnWithDlg(AlarmList.等到扫码超时.GetHashCode(), new string[] { "重试" }, new string[] { $"SN读取超时，读取内容=[{strSN}]，请重试" });
        //                stopwatch.Restart();
        //            }
        //        }
        //        if (strSN.Length != Param_System.Instance.SN长度._strParamVal || !strSN.Contains(Param_System.Instance.SN固定字符._strParamVal))
        //        {
        //            LogHelper.OnTest_ShowLog(Name, $"产品SN校验错误，读取内容=[{strSN}]", LogType.Err);
        //            AlarmMgr.GetIntance().WarnWithDlg(AlarmList.产品SN校验错误.GetHashCode(), new string[] { "重试" }, new string[] { $"产品SN校验错误，读取内容=[{strSN}]" });
        //            SNHelper.OnTest_ReflushSN("SN");
        //            UserConfig.b_isScan = false;
        //            return false;
        //        }
        //    }
        //    else
        //    {
        //        SNHelper.OnTest_ReflushSN("SN");
        //        Stopwatch stopwatch = new Stopwatch();
        //        stopwatch.Start();
        //        while (true)
        //        {
        //            if (扫码枪?.Fucntion_获取SN码(Param_System.Instance.SN长度._strParamVal, ref strSN, station_Param.触发超时时间._strParamVal) == 0 && strSN != "")
        //            {
        //                break;
        //            }
        //            Thread.Sleep(10);
        //            if (stopwatch.ElapsedMilliseconds > station_Param.扫码超时时间._strParamVal)
        //            {
        //                LogHelper.OnTest_ShowLog(Name, $"SN读取超时，读取内容=[{strSN}]", LogType.Err);
        //                StationStateHelper.OnTest_ShowStep(Name, $"{Name} SN读取超时", LogType.Warn);
        //                //AlarmMgr.GetIntance().WarnWithDlg(AlarmList.等到扫码超时.GetHashCode(), new string[] { "重试" }, new string[] { $"SN读取超时，读取内容=[{strSN}]，请重试" });
        //                stopwatch.Restart();
        //            }
        //        }
        //        if (strSN.Length != Param_System.Instance.SN长度._strParamVal || !strSN.Contains(Param_System.Instance.SN固定字符._strParamVal))
        //        {
        //            LogHelper.OnTest_ShowLog(Name, $"产品SN校验错误，读取内容=[{strSN}]", LogType.Err);
        //            AlarmMgr.GetIntance().WarnWithDlg(AlarmList.产品SN校验错误.GetHashCode(), new string[] { "重试" }, new string[] { $"产品SN校验错误，读取内容=[{strSN}]" });
        //            UserConfig.b_isScan = false;
        //            return false;
        //        }
        //        SNHelper.OnTest_ShowSN("SN", strSN);
        //    }

        //    LogHelper.OnTest_ShowLog(Name, $"读取产品SN=[{strSN}]", LogType.Info);
        //    LogHelper.OnTest_ShowLog(Name, $"等待双按钮启动", LogType.Warn);
        //    StationStateHelper.OnTest_ShowStep(Name, $"{Name} 等待双按钮启动", LogType.Warn);
        //    return true;
        //}

        private void Function_SetLimit()
        {
            stationData.TestResult.ErrValue1.Max = $"{Param_System.Instance.三角测试点位1误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue1.Min = $"{-1.0 * Param_System.Instance.三角测试点位1误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue2.Max = $"{Param_System.Instance.三角测试点位2误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue2.Min = $"{-1.0 * Param_System.Instance.三角测试点位2误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue3.Max = $"{Param_System.Instance.三角测试点位3误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue3.Min = $"{-1.0 * Param_System.Instance.三角测试点位3误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue4.Max = $"{Param_System.Instance.三角测试点位4误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue4.Min = $"{-1.0 * Param_System.Instance.三角测试点位4误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue5.Max = $"{Param_System.Instance.三角测试点位5误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue5.Min = $"{-1.0 * Param_System.Instance.三角测试点位5误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue6.Max = $"{Param_System.Instance.三角测试点位6误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue6.Min = $"{-1.0 * Param_System.Instance.三角测试点位6误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue7.Max = $"{Param_System.Instance.三角测试点位7误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue7.Min = $"{-1.0 * Param_System.Instance.三角测试点位7误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue8.Max = $"{Param_System.Instance.三角测试点位8误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue8.Min = $"{-1.0 * Param_System.Instance.三角测试点位8误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue9.Max = $"{Param_System.Instance.三角测试点位9误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue9.Min = $"{-1.0 * Param_System.Instance.三角测试点位9误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue10.Max = $"{Param_System.Instance.三角测试点位10误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue10.Min = $"{-1.0 * Param_System.Instance.三角测试点位10误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue11.Max = $"{Param_System.Instance.三角测试点位11误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue11.Min = $"{-1.0 * Param_System.Instance.三角测试点位11误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue12.Max = $"{Param_System.Instance.三角测试点位12误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue12.Min = $"{-1.0 * Param_System.Instance.三角测试点位12误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue13.Max = $"{Param_System.Instance.三角测试点位13误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue13.Min = $"{-1.0 * Param_System.Instance.三角测试点位13误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue14.Max = $"{Param_System.Instance.三角测试点位14误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue14.Min = $"{-1.0 * Param_System.Instance.三角测试点位14误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue15.Max = $"{Param_System.Instance.三角测试点位15误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue15.Min = $"{-1.0 * Param_System.Instance.三角测试点位15误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue16.Max = $"{Param_System.Instance.三角测试点位16误差绝对值上限._strParamVal}";
            stationData.TestResult.ErrValue16.Min = $"{-1.0 * Param_System.Instance.三角测试点位16误差绝对值上限._strParamVal}";
        }

        private bool Func_数据对比<T>(T testData, ref string strError)
        {
            {
                //1.获取数据值的类型
                //2.看数据能否转为double或int型，能转就比较，不能上下限就/
                //3.再看上下限能否转为double或int型,能转就比较
                bool result = true;
                PropertyInfo[] spData = testData.GetType().GetProperties();
                Type type = testData.GetType();
                int row = -1;
                foreach (var sp in spData)
                {
                    //获取点检数据
                    object obj = type.GetProperty(sp.Name).GetValue(testData, null);
                    TestInfo tempSp = obj as TestInfo;
                    double d_UpLimit = 0;
                    double d_DownLimit = 0;

                    //判断值类型及比较结果
                    bool re = true;
                    //测试内容

                    if (tempSp.Value.GetType() == typeof(double))
                    {
                        //上限比较
                        if (double.TryParse(tempSp.Max, out d_UpLimit))
                        {
                            re &= tempSp.Value <= d_UpLimit;
                        }
                        //下限比较
                        if (double.TryParse(tempSp.Min, out d_DownLimit))
                        {
                            re &= tempSp.Value >= d_DownLimit;
                        }
                    }
                    if (!re)
                    {
                        result = false;
                        strError = $"{tempSp.Name} 失败";
                        break;
                    }
                }
                return result;
            }
        }

        #endregion


        #region 对外函数

        public static void SetSN(string sn)
        {
            Station_三角测量.newSN = sn.Trim();
            Station_三角测量.isGetSN = true;
        }

        /// <summary>
        /// 因为四工位公用图卡，所以不能由每个工位都去操作图卡去安全位
        /// </summary>
        /// <param name="bmanual"></param>
        public void Function_图卡去安全位(bool bmanual = false)
        {
            var safePoint = station_Point.安全位置;
            MoveMulitAxisPosWaitInpos(
                new int[] { AxisX, AxisY, AxisZ, },
                new double[] { safePoint.pointX, safePoint.pointY, safePoint.pointZ },
                new double[] { (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High },
                0.5, bmanual, this);
        }



        #endregion
    }
}
